package com.yunhai.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.device.service.DeviceMaintainService;
import com.yunhai.model.entity.dms.DmsDeviceMaintainEntity;
import com.yunhai.model.vo.dms.DmsDeviceMaintainQuery;
import com.yunhai.model.vo.dms.DmsDeviceMaintainVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/deviceMaintain")
public class DeviceMaintainController {

	@Resource
	private DeviceMaintainService deviceMaintainService;


	/**
	 * 获取 DeviceMaintain 分页列表
	 */
	@GetMapping("/pagination")
	public Ret getDeviceMaintainPagination(PaginationVo paginationVo, DmsDeviceMaintainQuery dmsDeviceMaintainQuery ) throws Exception {
		IPage page = deviceMaintainService.getDeviceMaintainPagination(paginationVo, dmsDeviceMaintainQuery );
		return Ret.toPage(page);
	}


	/**
	 * 获取 DeviceMaintain 所有数据
	 */
	@GetMapping("/allList")
	public Ret getDeviceMaintainAllList( DmsDeviceMaintainQuery dmsDeviceMaintainQuery ) throws Exception {
		List<DmsDeviceMaintainEntity> list = deviceMaintainService.getDeviceMaintainAllList( dmsDeviceMaintainQuery );
		return Ret.ok(list);
	}


	/**
	 * 获取 DeviceMaintain 详情
	 */
	@GetMapping("/{id}")
	public Ret getDeviceMaintainDetailById(@PathVariable Long id) throws Exception {

	    DmsDeviceMaintainEntity dmsDeviceMaintainEntity = deviceMaintainService.getDeviceMaintainDetail(id);
		return Ret.ok(dmsDeviceMaintainEntity);
	}


	/**
	 * 新增 DeviceMaintain
	 * */
	@PostMapping("")
	public Ret addDeviceMaintain(@RequestBody DmsDeviceMaintainVo dmsDeviceMaintainVo) throws Exception {

		deviceMaintainService.addDeviceMaintain(dmsDeviceMaintainVo);
		return Ret.ok();
	}


	/**
	 * 更新 DeviceMaintain
	 * */
	@PutMapping("")
	public Ret updateDeviceMaintain(@RequestBody DmsDeviceMaintainVo dmsDeviceMaintainVo) throws Exception {

		deviceMaintainService.updateDeviceMaintain(dmsDeviceMaintainVo);
		return Ret.ok();
	}


	/**
	 * 删除 DeviceMaintain
	 * */
	@PostMapping("/batchRemove")
	public Ret batchRemoveDeviceMaintain( @RequestBody List<Long> ids ) throws Exception {

	    deviceMaintainService.batchRemoveDeviceMaintain(ids);
		return Ret.ok();
	}
}
